package com.hr.builder;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.ModelField;
import com.hr.SchedualItem;
import com.hr.SchedualScope;
//@Dependence({
//	"com.espirit.init.biz.SchedualDefineBuilder"
//})
@Component
public class SchedualItemBuilder extends ModelBuilderSupport {
	static final String EMPLOYEE = "employee";
	static final String DAY1 = "day1";
	static final String DAY2 = "day2";
	static final String DAY3 = "day3";
	static final String DAY4 = "day4";
	static final String DAY5 = "day5";
	static final String DAY6 = "day6";
	static final String DAY7 = "day7";
	
	@Override
	public boolean init() {
		return super.setClass(SchedualItem.class, "Schedual Item", "排班");
	}	

	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(EMPLOYEE, "Employee", "职员");
		addModelField(DAY1, "Day1", "Day1");
		addModelField(DAY2, "Day2", "Day2");
		addModelField(DAY3, "Day3", "Day3");
		addModelField(DAY4, "Day4", "Day4");
		addModelField(DAY5, "Day5", "Day5");
		addModelField(DAY6, "Day6", "Day6");
		addModelField(DAY7, "Day7", "Day7");
	}
	
	@Override
	protected void setDefaultLayoutButtons() {
	}
	
	@Override
	protected void addSearchFields() {
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(EMPLOYEE, DAY1, DAY2, DAY3, DAY4, DAY5, DAY6, DAY7));
	}
	
	
	@Override
	protected void addDetailFields() {
//		addDetailField(convertPropertyToField(EMPLOYEE, DAY1, DAY2, DAY3, DAY4, DAY5, DAY6, DAY7));
	}
	
	@Override
	protected Element convertFieldToElement(ModelField mf, boolean isListLayout) {
		Element element = super.convertFieldToElement(mf, isListLayout);
		String name = element.getName();
//		if (!isListLayout){
			
			if (name.startsWith("day")){
				Map<String, String> exProperties = element.safeExProperties();
				exProperties.put("model", SchedualScope.class.getName());
				exProperties.put("labelProperty", "scope");
				exProperties.put("property", "scope");
				exProperties.put("enableFreeText", "true");
				exProperties.put("showMoreIcon", "false");
				element.setExProperty(exProperties);
				element.setTagName("modelselect");
				
				element.addExProperty("showAddLink", "false");
			}	
			
//		}
		return element;
	}
	
}
